<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Linyou
 *
 * @author dragon.hu add @2016.2.19
 */
require_once 'BaseChannel.php';

//麟游
class Linyou implements BaseChannel 
{
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="73fd4c4715b6b2913d050f46faad683f"; //
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey=""; //
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		$orderLog->log("linyou", $_REQUEST);
		
		$game = $_REQUEST['game'];  //游戏名缩写
		$orderId = $_REQUEST['orderId'];  //麟游订单号
		$amount = $_REQUEST['amount'];  //商品总价，单位分
		$uid = $_REQUEST['uid'];  //用户标识
		$zone = $_REQUEST['zone'];  //区服ID
		$goodsId = $_REQUEST['goodsId'];  //商品ID
		$payTime = $_REQUEST['payTime'];  //平台支付完成时间
		$payChannel = $_REQUEST['payChannel'];  //支付方式
		$payExt = $_REQUEST['payExt'];  //扩展信息
		$sign = $_REQUEST['sign'];  //签名
		
		$mysign = $game.$orderId.$amount.$uid.$zone.$goodsId.$payTime.$payChannel.$payExt.'#'.$paymentKey;
		$result = array();

		if($sign == md5($mysign))
		{
			//验证通过,进行发货
			if(false == $orderLog->recordOrder(STATUS_SUCCESS, $amount/100, $payExt, "linyou", $platform,$orderId))
			{
				$result['errno'] = 1008;  //参数错误
				$result['errmsg'] = 'insert into db fail';
				$orderLog->log("linyou",array("order"=>$payExt,"money"=>$amount,"serverresult"=>"faild"));
			}
			else 
			{
				//支付成功
				$result['errno'] = 1000;  //成功
				$result['errmsg'] = '';
				$orderLog->log("linyou",array("order"=>$payExt,"money"=>$amount,"serverresult"=>"success"));
			}
		} 
		else 
		{
			$result['errno'] = 1001;  //验签失败
			$result['errmsg'] = 'sign failed';
			$orderLog->log("linyou","sign error!");
		}
		$result['data']['orderId'] = $orderId;
		$result['data']['amount'] = $amount;
		$result['data']['game'] = $game;
		$result['data']['zone'] = $zone;
		$result['data']['uid'] = $uid;
		
		$Ret = json_encode($result);
		return $Ret;
	}
}